#include "stack.h"
#include <iostream>
using namespace std;

template <class T>
Stack<T>::Stack(){
    T *arr = new T[MAXSIZE];
    if (!arr){
        exit(-1);
    }
    _top = arr;
    _base = arr;
    _size = MAXSIZE;
}
template <class T>
Stack<T>::~Stack(){
    if (!_base){
        delete[] _base;
    }
}
template <class T>
void Stack<T>::push(T const &e){
    if(_top-_base == _size){
        cout<<"err: stack is full!";
        return;
    }
    *_top++=e;
}
template <class T>
T Stack<T>::top(){
    if (_top!=_base)
    {
        return *(_top-1);
    }else{
        cout<<"err: empty stack";
        // return nullptr;
    }
}
template <class T>
T Stack<T>::pop(){
    if (_top!=_base)
    {
        return *--_top;
    }else{
        cout<<"err: empty stack";
        // return nullptr;
    }
}
template <class T>
void Stack<T>::info(){
    T *temp = _top;
    while(temp>_base){
        temp--;
        cout<<"=>"<<*temp<<endl;
    }
}

template <class T>
int Stack<T>::length(){
    return _top-_base;
}

template class Stack<char>;
template class Stack<int>;
template class Stack<float>;
